import { Button, Checkbox, Form, Input } from 'antd';
import React from 'react';
import axios from 'axios';
import {Navigate, useNavigate} from "react-router-dom"
import { Alert ,message} from 'antd';
const Login = () => {
  const navgitate = useNavigate()
  const onFinish = (values) => {
    axios.get("/login1",{params:{
        ...values
    }}).then(res=>{
         console.log(res.data);
         if (res.data.code === 3 ) {
           message. warning("您还没有注册，即将为您自动注册，稍等请登录")
         } else if (res.data.code === 0 ) {
            message.error("用户名密码错误")
         } else {
             message.success("登录成功")
             navgitate("/home")
         }
     
    })
    console.log('Success:', values);
  };

  const onFinishFailed = (errorInfo) => {
    console.log('Failed:', errorInfo);
  };

  return (
    <Form
      name="basic"
      labelCol={{
        span: 8,
      }}
      wrapperCol={{
        span: 16,
      }}
      initialValues={{
        remember: true,
      }}
      onFinish={onFinish}
      onFinishFailed={onFinishFailed}
      autoComplete="off"
    >
      <Form.Item
        label="Username"
        name="username"
        rules={[
          {
            required: true,
            message: 'Please input your username!',
          },
        ]}
      >
        <Input />
      </Form.Item>

      <Form.Item
        label="Password"
        name="password"
        rules={[
          {
            required: true,
            message: 'Please input your password!',
          },
        ]}
      >
        <Input.Password />
      </Form.Item>


      <Form.Item
        wrapperCol={{
          offset: 8,
          span: 16,
        }}
      >
        <Button type="primary" htmlType="submit">
          登陆
        </Button>
        {/* <Button type="primary" htmlType="submit">
          注册
        </Button> */}
        <Alert message="您如果没有注册，会自动帮您注册" type="success" />
      </Form.Item>
    </Form>
  );
};

export default Login;